﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Odbc;
using System.Data.OleDb;
using System.Data;

namespace UIDocument
{
    public partial class EmportExcel : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                if (System.IO.Path.GetExtension(FileUpload1.FileName) == ".xlsx")
                {
                    string s = FileUpload1.FileName;
                     FileUpload1.PostedFile.SaveAs(Server.MapPath("~/DocumentFile/Other/"+FileUpload1.FileName));
                     string path = Server.MapPath("~/DocumentFile/Other/"+FileUpload1.FileName);
                     OdbcConnection con = new OdbcConnection("Dsn=MYXLS");
                    con.Open();
                    OdbcCommand cmd = new OdbcCommand();
                    cmd.Connection = con;
                    cmd.CommandText = "select * from [Sheet1$]";
                    OdbcDataAdapter ad = new OdbcDataAdapter();
                    ad.SelectCommand = cmd;
                    DataTable tbl = new DataTable();
                    ad.Fill(tbl);
                    con.Close();
                }
            }   
        }
    }
}